//stores/member.ts
import { defineStore } from 'pinia'
import { reactive, ref } from 'vue'

export const useMemberStore = defineStore(
  'member', 
  () => {
    let userInfo = reactive({
      userName:'张三',
      userId:'123456789'
    })
    const setUserInfo = (val: any) => {
      userInfo.userName = val.userName
      userInfo.userId = val.userId
    }
    // 清理用户信息，退出时使用
    const clearUserInfo = () => {
      userInfo = {
        userName:'',
        userId:''
      }
    }
    return {
      userInfo,
      setUserInfo,
      clearUserInfo,
    }
  },
  // 默认持续化保存
  {
    persist:{
      // paths: ['token', 'userSettings'], // 指定需要持久化的状态路径
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key,value)
        },
      }
    }
  }
)
